{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Get them all with MixedRoute"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Creates 2 transmon pockets facing each other.\n",
    "\n",
    "Anchors are user-specified points through which the Routing must pass.\n",
    "\n",
    "Between anchors you can specify different connection algorythms."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%reload_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit_metal import designs\n",
    "from qiskit_metal import MetalGUI, Dict\n",
    "\n",
    "design = designs.DesignPlanar()\n",
    "gui = MetalGUI(design)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# enable rebuild of the same component\n",
    "design.overwrite_enabled = True\n",
    "design.delete_all_components()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "design.delete_all_components()  #needed only for rebuilds. will get a warning\n",
    "from qiskit_metal.qlibrary.qubits.transmon_pocket import TransmonPocket\n",
    "\n",
    "optionsQ = dict(\n",
    "    pad_width = '425 um', \n",
    "    pocket_height = '650um',\n",
    "    connection_pads=dict(  # pin connectors\n",
    "        a = dict(loc_W=+1,loc_H=+1), \n",
    "        b = dict(loc_W=-1,loc_H=+1, pad_height='30um'),\n",
    "        c = dict(loc_W=+1,loc_H=-1, pad_width='200um'),\n",
    "        d = dict(loc_W=-1,loc_H=-1, pad_height='50um')\n",
    "    )\n",
    ")\n",
    "\n",
    "q0 = TransmonPocket(design, 'Q0', options = dict(pos_x='-5.0mm', pos_y='0.0mm', **optionsQ))\n",
    "q1 = TransmonPocket(design, 'Q1', options = dict(pos_x='5.0mm', pos_y='0.0mm', **optionsQ))\n",
    "\n",
    "gui.rebuild()\n",
    "gui.autoscale()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Single CPW using one meander and 3 simple segments"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit_metal.qlibrary.tlines.mixed_path import RouteMixed\n",
    "import numpy as np\n",
    "from collections import OrderedDict\n",
    "ops=dict(fillet='90um')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "anchors = OrderedDict()\n",
    "anchors[0] = np.array([-3., 1.])\n",
    "anchors[1] = np.array([0, 2])\n",
    "anchors[2] = np.array([3., 1])\n",
    "anchors[3] = np.array([4., .5])\n",
    "\n",
    "between_anchors = OrderedDict() # S, M, PF\n",
    "between_anchors[0] = \"S\"\n",
    "between_anchors[1] = \"M\"\n",
    "between_anchors[2] = \"S\"\n",
    "between_anchors[3] = \"M\"\n",
    "between_anchors[4] = \"S\"\n",
    "\n",
    "jogsS = OrderedDict()\n",
    "jogsS[0] = [\"R\", '200um']\n",
    "jogsS[1] = [\"R\", '200um']\n",
    "jogsS[2] = [\"L\", '200um']\n",
    "jogsS[3] = [\"L\", '500um']\n",
    "jogsS[4] = [\"R\", '200um']\n",
    "\n",
    "jogsE = OrderedDict()\n",
    "jogsE[0] = [\"L\", '200um']\n",
    "jogsE[1] = [\"L\", '200um']\n",
    "jogsE[2] = [\"R\", '200um']\n",
    "jogsE[3] = [\"R\", '500um']\n",
    "jogsE[4] = [\"L\", '200um']\n",
    "\n",
    "\n",
    "optionsR = {'pin_inputs': {\n",
    "              'start_pin': {'component': 'Q0', 'pin': 'b'}, \n",
    "              'end_pin': {'component': 'Q1', 'pin': 'a'}\n",
    "            },\n",
    "            'total_length': '32mm',\n",
    "            'chip': 'main',\n",
    "            'layer': '1',\n",
    "            'trace_width': 'cpw_width',\n",
    "            'step_size': '0.25mm',\n",
    "            'anchors': anchors,\n",
    "            'between_anchors': between_anchors,\n",
    "            'advanced': {'avoid_collision': 'true'},\n",
    "            'meander': {\n",
    "              'spacing': '200um',\n",
    "              'asymmetry': '0um'\n",
    "            },\n",
    "            'snap': 'true',\n",
    "            'lead': {\n",
    "              'start_straight': '0.3mm',\n",
    "              'end_straight': '0.3mm',\n",
    "              'start_jogged_extension': jogsS,\n",
    "              'end_jogged_extension': jogsE\n",
    "            },\n",
    "            **ops\n",
    "          }\n",
    "\n",
    "qa = RouteMixed(design, 'line', optionsR)\n",
    "\n",
    "gui.rebuild()\n",
    "gui.autoscale()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Single CPW using the pathfinder segments"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "anchors = OrderedDict()\n",
    "anchors[0] = np.array([-3., -1.])\n",
    "anchors[1] = np.array([0.2, -2])\n",
    "anchors[2] = np.array([3., -1.7])\n",
    "\n",
    "between_anchors = OrderedDict() # S, M, PF\n",
    "between_anchors[0] = \"S\"\n",
    "between_anchors[1] = \"S\"\n",
    "between_anchors[2] = \"PF\"\n",
    "between_anchors[3] = \"S\"\n",
    "\n",
    "jogsS = OrderedDict()\n",
    "jogsS[0] = [\"L\", '200um']\n",
    "jogsS[1] = [\"L\", '200um']\n",
    "jogsS[2] = [\"R\", '200um']\n",
    "jogsS[3] = [\"R\", '500um']\n",
    "jogsS[4] = [\"L\", '200um']\n",
    "\n",
    "jogsE = OrderedDict()\n",
    "jogsE[0] = [\"R\", '200um']\n",
    "jogsE[1] = [\"R\", '200um']\n",
    "jogsE[2] = [\"L\", '200um']\n",
    "jogsE[3] = [\"L\", '500um']\n",
    "jogsE[4] = [\"R\", '200um']\n",
    "\n",
    "\n",
    "optionsR = {'pin_inputs': {\n",
    "              'start_pin': {'component': 'Q0', 'pin': 'd'}, \n",
    "              'end_pin': {'component': 'Q1', 'pin': 'c'}\n",
    "            },\n",
    "            'total_length': '22mm',\n",
    "            'chip': 'main',\n",
    "            'layer': '1',\n",
    "            'trace_width': 'cpw_width',\n",
    "            'step_size': '0.25mm',\n",
    "            'anchors': anchors,\n",
    "            'between_anchors': between_anchors,\n",
    "            'advanced': {'avoid_collision': 'true'},\n",
    "            'meander': {\n",
    "              'spacing': '200um',\n",
    "              'asymmetry': '0um'\n",
    "            },\n",
    "            'snap': 'true',\n",
    "            'lead': {\n",
    "              'start_straight': '0.3mm',\n",
    "              'end_straight': '0.3mm',\n",
    "              'start_jogged_extension': jogsS,\n",
    "              'end_jogged_extension': jogsE\n",
    "            },\n",
    "            **ops\n",
    "          }\n",
    "\n",
    "qb = RouteMixed(design, 'line2', optionsR)\n",
    "\n",
    "gui.rebuild()\n",
    "gui.autoscale()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# create an obstacle\n",
    "TransmonPocket(design, options = dict(pos_x='1.0mm', pos_y='-2.0mm', **optionsQ))\n",
    "TransmonPocket(design, options = dict(pos_x='1.0mm', pos_y='-1.0mm', **optionsQ))\n",
    "TransmonPocket(design, options = dict(pos_x='-2.0mm', pos_y='-1.0mm', **optionsQ))\n",
    "\n",
    "gui.rebuild()\n",
    "gui.autoscale()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "anchors = OrderedDict()\n",
    "anchors[0] = np.array([0.,-1.5])\n",
    "\n",
    "between_anchors = OrderedDict() # S, M, PF\n",
    "between_anchors[0] = \"S\"\n",
    "between_anchors[1] = \"PF\"\n",
    "\n",
    "jogsS = OrderedDict()\n",
    "jogsS[0] = [\"R\", '200um']\n",
    "jogsS[1] = [\"R\", '200um']\n",
    "jogsS[2] = [\"L\", '200um']\n",
    "jogsS[3] = [\"L\", '500um']\n",
    "\n",
    "jogsE = OrderedDict()\n",
    "jogsE[0] = [\"L\", '200um']\n",
    "jogsE[1] = [\"L\", '200um']\n",
    "jogsE[2] = [\"R\", '200um']\n",
    "jogsE[3] = [\"R\", '500um']\n",
    "\n",
    "optionsR = {'pin_inputs': {\n",
    "              'start_pin': {'component': 'Q0', 'pin': 'c'}, \n",
    "              'end_pin': {'component': 'Q1', 'pin': 'd'}\n",
    "            },\n",
    "            'total_length': '12mm',\n",
    "            'chip': 'main',\n",
    "            'layer': '1',\n",
    "            'trace_width': 'cpw_width',\n",
    "            'step_size': '0.25mm',\n",
    "            'anchors': anchors,\n",
    "            'between_anchors': between_anchors,\n",
    "            'advanced': {'avoid_collision': 'true'},\n",
    "            'meander': {\n",
    "              'spacing': '200um',\n",
    "              'asymmetry': '0um'\n",
    "            },\n",
    "            'snap': 'true',\n",
    "            'lead': {\n",
    "              'start_straight': '0.3mm',\n",
    "              'end_straight': '0.3mm',\n",
    "              'start_jogged_extension': jogsS,\n",
    "              'end_jogged_extension': jogsE\n",
    "            },\n",
    "            **ops\n",
    "          }\n",
    "\n",
    "qc = RouteMixed(design, 'line3', optionsR)\n",
    "\n",
    "gui.rebuild()\n",
    "gui.autoscale()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
